var color = ["#6BD98D", "#FABF32",  "#FABF32","#B3C9D5", "#1AAFDE", "#07B345", "#FF8300"];
export function pieChartFun(echartData, data) {
	let angle = 0; //角度，用来做简单的动画效果的
	//获取圆上面某点的坐标(x0,y0表示坐标，r半径，angle角度)
	function getCirlPoint(x0, y0, r, angle) {
		let x1 = x0 + r * Math.cos((angle * Math.PI) / 180);
		let y1 = y0 + r * Math.sin((angle * Math.PI) / 180);
		return {
			x: x1,
			y: y1,
		};
	}
	let formatNumber = function(num) {
		let reg = /(?=(\B)(\d{3})+$)/g;
		return num.toString().replace(reg, ',');
	};
	let option = {
		color: color,
		tooltip: {
			trigger: 'item',
			formatter: function(params) {
				// 自定义显示内容
				return params.name + '：'+  params.data.count;
			}
		},
		legend: {
			orient: 'vertical',
			x: '42%',
			y: 'center',
			itemGap: 10,
			icon: 'circle',
			itemWith: 8,
			itemHeight: 8,
			align: 'left',
			textStyle: {
				color: '#EDFBFF',
				fontSize: 13,
				padding: [0, 0, 0, 0],
			},
			formatter(name) {
				let then = option.series[0].data; //获取series中的data
				let total = 0;

				for (let i = 0; i < then.length; i++) {
					if (then[i].name != '' && then[i].name != null && then[i].name != undefined) {
						total += parseInt(then[i].count);
					}
				}
				var str = '';
				var p = 0;
				for (let i = 0; i < then.length; i++) {
					if (then[i].name == name) {
						if(data?.unit == 'name'){
							str = name;
						}else if(data?.unit == 'none'){
							str = name + '  ' + then[i].value ;
						}else if(data?.unit != 'none'){
							str = name + '  ' + then[i].value + data.unit + '  ' + then[i].value + '%';
						} else {
							str = name + '  ' +  then[i].value + '%';
						}
						
					}
				}
				return str;
			},
		},
		series: [{
				type: 'pie',
				radius: data.radius?data.radius:['55%', '80%'],
				center: data.center?data.center:['23%', '50%'],
				data: echartData,
				hoverAnimation: false,
				labelLine: {
					normal: {
						show: false,
						length: 20,
						length2: 120,
						lineStyle: {
							color: '#e6e6e6',
						},
					},
				},
				label: {
					normal: {
						show: false,
						formatter: (params) => {
							return '{icon|●}{name|' + params.name + '}{value|' + formatNumber(params
								.value) + '}';
						},
						padding: [0, -100, 25, -100],
						rich: {
							icon: {
								fontSize: 16,
							},
							name: {
								fontSize: 14,
								padding: [0, 10, 0, 4],
								color: '#666666',
							},
							value: {
								fontSize: 18,
								fontWeight: 'bold',
								color: '#333333',
							},
						},
					},
				},
			},

		],
	}
	return option
}